package com.parkinginfo.dbhelper;

/*
 * Author: Deepika Gohil
 * 
 */

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class PlacesSQLiteOpenHelper extends SQLiteOpenHelper {
	
	public static final int VERSION = 1;
	public static final String DB_NAME  = "sfparkinginformer.sqlite";
	public static final String Places_TABLE  = "places";
	public static final String Place_ID = "id";
	public static final String Place_NAME = "name";

	public static final String Place_LOCATION = "location";
	public static final String Place_LAT = "lattitide";
	public static final String Place_LON = "longitude";

	
	public PlacesSQLiteOpenHelper(Context context) {
		super(context, DB_NAME, null, VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		dropAndCreate(db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// We do nothing here yet
		// Later, if we change the way the database is structured, 
		// we'd increment the VERSION constant and Android would 
		// automatically call onUpgrade where we'd call different 
		// sql to modify the db here.
	}

	protected void dropAndCreate(SQLiteDatabase db) {
		db.execSQL("drop table if exists " + Places_TABLE + ";");
		createTables(db);
		addDetails(db);
	}
	
	protected void createTables(SQLiteDatabase db) {
		db.execSQL(
				"create table " + Places_TABLE +" (" +
				Place_ID + " integer primary key autoincrement not null," +
				Place_NAME + " text," +
				Place_LOCATION + " text," +
				Place_LAT + " text," +
				Place_LON + " text" +
				");"
			);
	}
	
	protected void addDetails(SQLiteDatabase db) {
		db.execSQL(
				"INSERT INTO " + Places_TABLE + "(" + Place_NAME +","+ Place_LOCATION +"," + Place_LAT +"," +Place_LON + " ) VALUES " +
						"( 'Embarcadreo' , 'Embarcadero, Sam Francisco, CA', '37.796441' , '-122.395334');"
				); 
		
		db.execSQL(
				"INSERT INTO " + Places_TABLE + "(" + Place_NAME +","+ Place_LOCATION +"," + Place_LAT +"," +Place_LON + " ) VALUES " +
						"( 'Montgomery' , 'Montgomery, Sam Francisco, CA', '37.789234' , '-122.401385');"
				); 
		
		db.execSQL(
				"INSERT INTO " + Places_TABLE + "(" + Place_NAME +","+ Place_LOCATION +"," + Place_LAT +"," +Place_LON + " ) VALUES " +
						"( 'Financial District' , 'Financial District, San Francisco, CA', '37.79578','-122.400012');"
				); 
		
		db.execSQL(
				"INSERT INTO " + Places_TABLE + "(" + Place_NAME +","+ Place_LOCATION +"," + Place_LAT +"," +Place_LON + " ) VALUES " +
						"( 'Powell' , 'Powell, San Francisco, CA', '37.784418' , '-122.407222');"
				); 
		db.execSQL(
				"INSERT INTO " + Places_TABLE + "(" + Place_NAME +","+ Place_LOCATION +"," + Place_LAT +"," +Place_LON + " ) VALUES " +
						"( 'Civic Center' , 'Civic Center, San Francisco, CA', '37.780247' , '-122.4125');"
				); 
		db.execSQL(
				"INSERT INTO " + Places_TABLE + "(" + Place_NAME +","+ Place_LOCATION +"," + Place_LAT +"," +Place_LON + " ) VALUES " +
						"( 'Castro' , 'Castro, San Francisco, CA', '37.762437' , '-122.435675');"
				); 
		db.execSQL(
				"INSERT INTO " + Places_TABLE + "(" + Place_NAME +","+ Place_LOCATION +"," + Place_LAT +"," +Place_LON + " ) VALUES " +
						"( 'FisherMans Wharf' , 'FisherMans Wharf,CA', '37.806529' , '-122.411556');"
				); 
		db.execSQL(
				"INSERT INTO " + Places_TABLE + "(" + Place_NAME +","+ Place_LOCATION +"," + Place_LAT +"," +Place_LON + " ) VALUES " +
						"( 'Lombard Street' , 'Lombard Street, San Francisco, CA', '37.799815' , '-122.432842');"
				);
		db.execSQL(
				"INSERT INTO " + Places_TABLE + "(" + Place_NAME +","+ Place_LOCATION +"," + Place_LAT +"," +Place_LON + " ) VALUES " +
						"( 'Inner Richmond' , 'Inner Richmond, San Francisco, CA', '37.780755' , '-122.466445');"
				);
	}
}
